package Clothing.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Utils {
    
    /**
     * 把普通字符串转化为日期 yyyy-MM-dd
     *
     * @param dateStr
     * @return
     */
     public static Date convertToDate(String dateStr){
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");  
         ParsePosition pos = new ParsePosition(0);  
         Date strtodate = formatter.parse(dateStr, pos);  
         return strtodate;
     }
     
     /** 
      * 将短时间格式时间转换为字符串 yyyy-MM-dd 
      *  
      * @param dateDate 
      * @param k 
      * @return 
      */  
     public static String dateToStr(java.util.Date dateDate) {  
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");  
         String dateString = formatter.format(dateDate);  
         return dateString;  
     }  
     
     /**
      * 计算俩个时间差
      * @return
      * @throws ParseException 
      */
     public static int getDiffDate(String date,String date2) throws ParseException {
         DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
         Date d1 = df.parse(date2); 
         Date d2 = df.parse(date);
         long diff = d2.getTime() - d1.getTime();
         long days = diff / 1000;
         return Integer.valueOf(String.valueOf(days));
     }

}
